package com.xcf.controller.business.common;

import java.util.List;

import javax.annotation.Resource;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.xcf.controller.base.BaseController;
import com.xcf.service.business.common.businesstype.BusinessTypeMaintainService;
import com.xcf.util.PageData;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Controller
@RequestMapping(value="/businessTypeMaintain")
public class BusinessTypeMaintainController extends BaseController{
	String menuUrl = "businessTypeMaintain/indexbusinness"; //菜单地址(权限用)
	@Resource
	private BusinessTypeMaintainService business;
	/**
	 * 业务类别管理列表查询
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/indexbusinness")
	public ModelAndView businessTypeMaintainList()throws Exception{
		ModelAndView view = this.getModelAndView();
		try {
			//列表查询
			List<PageData> listBusinessTypeMaintain = business.listBusinessTypeMaintain();
			view.addObject("businessType",listBusinessTypeMaintain);
			view.setViewName("/business/common/businesstype/business_type_maintain");
			
		} catch (Exception e) {
		}
		return view;
	}
//	/**
//	 * 保存业务类别管理新增信息
//	 * @return
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/saveBusinessTypeMainTain")
//	public ModelAndView saveBusinessTypeMaintain()throws Exception{
//		ModelAndView mv = this.getModelAndView();
//		PageData pd = new PageData();
//		pd = this.getPageData();
//		if(pd.getString("ID")==null){
//			pd.put("ID", this.get32UUID());
//			business.saveBusinessTypeMaintainInfo(pd);
//		}
//		
//		mv.addObject("msg","success");
//		
//		mv.setViewName("save_result");
//		return mv;
//		
//	}
	/**
	 * 保存或更新业务类别管理数据
	 */
	@RequestMapping(value="/updateBusinessTypeMaintain")
	@ResponseBody
	public String updateBusinessTypeMaintain()throws Exception{
		PageData pd = new PageData();
		pd = this.getPageData();
		String data = pd.getString("dataJsonStr");

		JSONArray items = JSONArray.fromObject(data);
		for(int i=0,size=items.size();i<size;i++){
			JSONObject item = items.getJSONObject(i);
			String id = item.getString("ID").trim();
			String SERIAL = item.getString("SERIAL");
			String BUSINESS_TYPE_CHINESE_NAME = item.getString("BUSINESS_TYPE_CHINESE_NAME");
			String BUSINESS_TYPE_CODE = item.getString("BUSINESS_TYPE_CODE");
			int ARRANGEMENT_ORDER = Integer.parseInt(item.getString("ARRANGEMENT_ORDER"));
			String ENABLE = item.getString("ENABLE");
			PageData pdq = new PageData();
			pdq.put("ID", id);
			pdq.put("SERIAL", SERIAL);
			pdq.put("BUSINESS_TYPE_CHINESE_NAME", BUSINESS_TYPE_CHINESE_NAME);
			pdq.put("BUSINESS_TYPE_CODE",BUSINESS_TYPE_CODE);
			pdq.put("ARRANGEMENT_ORDER", ARRANGEMENT_ORDER);
			pdq.put("ENABLE", ENABLE);
			if(id==null||id.equals("on")){
				pdq.put("ID", this.get32UUID());
				business.saveBusinessTypeMaintainInfo(pdq);
			}else{
				business.updateBusinessTypeMaintainInfo(pdq);
			}
			
		}
		return null;
		
	}
	/**
	 * 删除业务类别管理信息
	 * @throws Exception
	 */
	@RequestMapping(value="/deleteBusinessTypeMaintain")
	@ResponseBody
	public String deleteBusinessTypeMaintain() throws Exception{
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		String data = pd.getString("dataJsonStr");

		JSONArray items = JSONArray.fromObject(data);
		for(int i=0,size=items.size();i<size;i++){
			JSONObject item = items.getJSONObject(i);
			String id = item.getString("ID").trim();
			PageData pdq = new PageData();
			pdq.put("ID", id);
			business.deleteU(pdq);
		}
		return null;
		
	}
}
